home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / info / elisp-24.z / elisp-24
Encoding:
GNU Info File  |  1994-08-02  |  47.1 KB  |  1,095 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.  
  4.    This version is newer than the second printed edition of the GNU
  5. Emacs Lisp Reference Manual.  It corresponds to Emacs Version 19.19.
  6.  
  7.    Published by the Free Software Foundation 675 Massachusetts Avenue
  8. Cambridge, MA 02139 USA
  9.  
  10.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  11.  
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.  
  16.    Permission is granted to copy and distribute modified versions of
  17. this manual under the conditions for verbatim copying, provided that
  18. the entire resulting derived work is distributed under the terms of a
  19. permission notice identical to this one.
  20.  
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that this permission notice may be stated in a
  24. translation approved by the Foundation.
  25.  
  26.    Permission is granted to copy and distribute modified versions of
  27. this manual under the conditions for verbatim copying, provided also
  28. that the section entitled "GNU Emacs General Public License" is included
  29. exactly as in the original, and provided that the entire resulting
  30. derived work is distributed under the terms of a permission notice
  31. identical to this one.
  32.  
  33.    Permission is granted to copy and distribute translations of this
  34. manual into another language, under the above conditions for modified
  35. versions, except that the section entitled "GNU Emacs General Public
  36. License" may be included in a translation approved by the Free Software
  37. Foundation instead of in the original English.
  38.  
  39. 
  40. File: elisp,  Node: Examining Properties,  Next: Changing Properties,  Up: Text Properties
  41.  
  42. Examining Text Properties
  43. -------------------------
  44.  
  45.    The simplest way to examine text properties is to ask for the value
  46. of a particular property of a particular character.  For that, use
  47. `get-text-property'.  Use `text-properties-at' to get the entire
  48. property list of a character.  *Note Property Search::, for functions
  49. to examine the properties of a number of characters at once.
  50.  
  51.    These functions handle both strings and buffers.  Keep in mind that
  52. positions in a string start from 0, whereas positions in a buffer start
  53. from 1.
  54.  
  55.  - Function: get-text-property POS PROP &optional OBJECT
  56.      This function returns the value of the PROP property of the
  57.      character after position POS in OBJECT (a buffer or string).  The
  58.      argument OBJECT is optional and defaults to the current buffer.
  59.  
  60.      If there is no PROP property strictly speaking, but the character
  61.      has a category which is a symbol, then `get-text-property' returns
  62.      the PROP property of that symbol.
  63.  
  64.  - Function: text-properties-at POSITION &optional OBJECT
  65.      This function returns the list of properties held by the character
  66.      at POSITION in the string or buffer OBJECT.  If OBJECT is `nil',
  67.      it defaults to the current buffer.
  68.  
  69.  - Function: text-property-any START END PROP VALUE &optional OBJECT
  70.      This function returns non-`nil' if at least one character between
  71.      START and END has a property PROP whose value is VALUE.  More
  72.      precisely, it returns the position of the first such character.
  73.      Otherwise, it returns `nil'.
  74.  
  75.      The optional fifth argument, OBJECT, specifies the string or
  76.      buffer to scan.  Positions are relative to OBJECT.
  77.  
  78.  - Function: text-property-not-all START END PROP VALUE &optional OBJECT
  79.      This function returns non-`nil' if at least one character between
  80.      START and END has a property PROP whose value differs from VALUE.
  81.      More precisely, it returns the position of the first such
  82.      character.  Otherwise, it returns `nil'.
  83.  
  84.      The optional fifth argument, OBJECT, specifies the string or
  85.      buffer to scan.  Positions are relative to OBJECT.
  86.  
  87. 
  88. File: elisp,  Node: Changing Properties,  Next: Property Search,  Prev: Examining Properties,  Up: Text Properties
  89.  
  90. Changing Text Properties
  91. ------------------------
  92.  
  93.    The primitives for changing properties apply to a specified range of
  94. text.  The function `set-text-properties' (see end of section) sets the
  95. entire property list of the text in that range; more often, it is
  96. useful to add, change, or delete just certain properties specified by
  97. name.
  98.  
  99.    Since text properties are considered part of the buffer's contents,
  100. and can affect how the buffer looks on the screen, any change in the
  101. text properties is considered a buffer modification.  Buffer text
  102. property changes are undoable.
  103.  
  104.  - Function: add-text-properties START END PROPS &optional OBJECT
  105.      This function modifies the text properties for the text between
  106.      START and END in the string or buffer OBJECT.  If OBJECT is `nil',
  107.      it defaults to the current buffer.
  108.  
  109.      The argument PROPS specifies which properties to change.  It
  110.      should have the form of a property list (*note Property Lists::.):
  111.      a list whose elements include the property names followed
  112.      alternately by the corresponding values.
  113.  
  114.      The return value is `t' if the function actually changed some
  115.      property's value; `nil' otherwise (if PROPS is `nil' or its values
  116.      agree with those in the text).
  117.  
  118.      For example, here is how to set the `comment' property to `t' for
  119.      a range of text:
  120.  
  121.           (add-text-properties (region-beginning)
  122.                                (region-end)
  123.                                (list 'comment t))
  124.  
  125.  - Function: put-text-property START END PROP VALUE &optional OBJECT
  126.      This function sets the PROP property to VALUE for the text between
  127.      START and END in the string or buffer OBJECT.  If OBJECT is `nil',
  128.      it defaults to the current buffer.
  129.  
  130.  - Function: remove-text-properties START END PROPS &optional OBJECT
  131.      This function deletes specified text properties from the text
  132.      between START and END in the string or buffer OBJECT.  If OBJECT
  133.      is `nil', it defaults to the current buffer.
  134.  
  135.      The argument PROPS specifies which properties to delete.  It
  136.      should have the form of a property list (*note Property Lists::.):
  137.      a list whose elements include the property names followed by the
  138.      corresponding values.  The property names mentioned in PROPS are
  139.      the ones deleted from the text.  The values associated in PROPS
  140.      with these names do not matter.
  141.  
  142.      The return value is `t' if the function actually changed some
  143.      property's value; `nil' otherwise (if PROPS is `nil' or if none of
  144.      the text had any of those properties).
  145.  
  146.  - Function: set-text-properties START END PROPS &optional OBJECT
  147.      This function completely replaces the text property list for the
  148.      text between START and END in the string or buffer OBJECT.  If
  149.      OBJECT is `nil', it defaults to the current buffer.
  150.  
  151.      The argument PROPS is the new property list.  It should have the
  152.      form of a list whose elements include the property names followed
  153.      by the corresponding values.
  154.  
  155.      After `set-text-properties' returns, all the characters in the
  156.      specified range have identical properties.
  157.  
  158.      If PROPS is `nil', the effect is to get rid of all properties from
  159.      the specified range of text.  Here's an example:
  160.  
  161.           (set-text-properties (region-beginning)
  162.                                (region-end)
  163.                                nil)
  164.  
  165. 
  166. File: elisp,  Node: Property Search,  Next: Special Properties,  Prev: Changing Properties,  Up: Text Properties
  167.  
  168. Property Search Functions
  169. -------------------------
  170.  
  171.    In typical use of text properties, most of the time several or many
  172. consecutive characters have the same value for a property.  Rather than
  173. writing your programs to examine characters one by one, it is much
  174. faster to process chunks of text that have the same property value.
  175.  
  176.    Here are functions you can use to do this.  In all cases, OBJECT
  177. defaults to the current buffer.
  178.  
  179.  - Function: next-property-change POS &optional OBJECT
  180.      The function scans the text forward from position POS in the
  181.      string or buffer OBJECT till it finds a change in some text
  182.      property, then returns the position of the change.  In other
  183.      words, it returns the position of the first character beyond POS
  184.      whose properties are not identical to those of the character just
  185.      after POS.
  186.  
  187.      The value is `nil' if the properties remain unchanged all the way
  188.      to the end of OBJECT.  If the value is non-`nil', it is a position
  189.      greater than POS, never equal.
  190.  
  191.      Here is an example of how to scan the buffer by chunks of text
  192.      within which all properties are constant:
  193.  
  194.           (while (not (eobp))
  195.             (let ((plist (text-properties-at (point)))
  196.                   (next-change
  197.                    (or (next-property-change (point) (current-buffer))
  198.                        (point-max))))
  199.               PROCESS TEXT FROM POINT TO NEXT-CHANGE...
  200.               (goto-char next-change)))
  201.  
  202.  - Function: next-single-property-change POS PROP &optional OBJECT
  203.      The function scans the text forward from position POS in the
  204.      string or buffer OBJECT till it finds a change in the PROP
  205.      property, then returns the position of the change.  In other
  206.      words, it returns the position of the first character beyond POS
  207.      whose PROP property differs from that of the character just after
  208.      POS.
  209.  
  210.      The value is `nil' if the properties remain unchanged all the way
  211.      to the end of OBJECT.  If the value is non-`nil', it is a position
  212.      greater than POS, never equal.
  213.  
  214.  - Function: previous-property-change POS &optional OBJECT
  215.      This is like `next-property-change', but scans back from POS
  216.      instead of forward.  If the value is non-`nil', it is a position
  217.      always strictly less than POS.
  218.  
  219.  - Function: previous-single-property-change POS PROP &optional OBJECT
  220.      This is like `next-property-change', but scans back from POS
  221.      instead of forward.  If the value is non-`nil', it is a position
  222.      always strictly less than POS.
  223.  
  224. 
  225. File: elisp,  Node: Special Properties,  Next: Sticky Properties,  Prev: Property Search,  Up: Text Properties
  226.  
  227. Special Properties
  228. ------------------
  229.  
  230.    If a character has a `category' property, we call it the "category"
  231. of the character.  It should be a symbol.  The properties of the symbol
  232. serve as defaults for the properties of the character.
  233.  
  234.    You can use the property `face' to control the font and color of
  235. text.  *Note Faces::, for more information.  This feature is temporary;
  236. in the future, we may replace it with other ways of specifying how to
  237. display text.
  238.  
  239.    The property `mouse-face' is used instead of `face' when the mouse
  240. is on or near the character.  For this purpose, "near" means that all
  241. text between the character and where the mouse is have the same
  242. `mouse-face' property value.
  243.  
  244.    You can specify a different keymap for a portion of the text by means
  245. of a `local-map' property.  The property's value, for the character
  246. after point, replaces the buffer's local map.  *Note Active Keymaps::.
  247.  
  248.    If a character has the property `read-only', then modifying that
  249. character is not allowed.  Any command that would do so gets an error.
  250. Insertion next to a read-only character is also an error if inserting
  251. ordinary text there would inherit the `read-only' property due to
  252. stickiness.  Thus, you can control permission to insert next to
  253. read-only text by controlling the stickiness.  *Note Sticky
  254. Properties::.
  255.  
  256.    Since changing properties counts as modifying the buffer, it is not
  257. possible to remove a `read-only' property unless you know the special
  258. trick: bind `inhibit-read-only' to a non-`nil' value and then remove
  259. the property.  *Note Read Only Buffers::.
  260.  
  261.    A non-`nil' `invisible' property means a character does not appear
  262. on the screen.  This works much like selective display.  Details of
  263. this feature are likely to change in future versions, so check the
  264. `etc/NEWS' file in the version you are using.
  265.  
  266.    If a character has the property `modification-hooks', then its value
  267. should be a list of functions; modifying that character calls all of
  268. those functions.  Each function receives two arguments: the beginning
  269. and end of the part of the buffer being modified.  Note that if a
  270. particular modification hook function appears on several characters
  271. being modified by a single primitive, you can't predict how many times
  272. the function will be called.
  273.  
  274.    Insertion of text does not, strictly speaking, change any existing
  275. character, so there is a special rule for insertion.  It compares the
  276. `read-only' properties of the two surrounding characters; if they are
  277. non-`nil' and `eq' to each other, then the insertion is not allowed.
  278. Assuming insertion is allowed, it then calls the functions listed in
  279. the `insert-in-front-hooks' property of the following character and in
  280. the `insert-behind-hooks' property of the preceding character.  These
  281. functions receive two arguments, the beginning and end of the inserted
  282. text.
  283.  
  284.    See also *Note Change Hooks::, for other hooks that are called when
  285. you change text in a buffer.
  286.  
  287.    The special properties `point-entered' and `point-left' record hook
  288. functions that report motion of point.  Each time point moves, Emacs
  289. compares these two property values:
  290.  
  291.    * the `point-left' property of the character after the old location,
  292.      and
  293.  
  294.    * the `point-entered' property of the character after the new
  295.      location.
  296.  
  297. If these two values differ, each of them is called (if not `nil') with
  298. two arguments: the old value of point, and the new one.
  299.  
  300.    The same comparison is made for the characters before the old and new
  301. locations.  The result may be to execute two `point-left' functions
  302. (which may be the same function) and/or two `point-entered' functions
  303. (which may be the same function).  The `point-left' functions are
  304. always called before the `point-entered' functions.
  305.  
  306.    A primitive function may examine characters at various positions
  307. without moving point to those positions.  Only an actual change in the
  308. value of point runs these hook functions.
  309.  
  310.  - Variable: inhibit-point-motion-hooks
  311.      When this variable is non-`nil', `point-left' and `point-entered'
  312.      hooks are not run.
  313.  
  314. 
  315. File: elisp,  Node: Sticky Properties,  Next: Not Intervals,  Prev: Special Properties,  Up: Text Properties
  316.  
  317. Stickiness of Text Properties
  318. -----------------------------
  319.  
  320.    Inserting a string with no text properties into the buffer normally
  321. gives the inserted text the same properties as the preceding character.
  322. You can control this copying of properties by setting the
  323. `front-sticky' and `rear-nonsticky' properties of a character.
  324.  
  325.    If you make a character's `front-sticky' property `t', then
  326. insertion before the character receives its properties.  If you make the
  327. `rear-nonsticky' property `t', then insertion after that character does
  328. *not* receive its properties.  You can regard characters as being
  329. normally "rear-sticky" by default, but not "front-sticky"; thus, by
  330. default, insertion normally receives properties from the previous
  331. character only.
  332.  
  333.    If neither side of an insertion is suitably sticky, then the inserted
  334. text gets no properties.  If both sides are sticky, then the inserted
  335. text gets the properties of both sides, with the previous character's
  336. properties taking precedence when both sides have a property in common.
  337.  
  338.    You can also specify stickiness for individual properties.  To do so,
  339. use a list of property names as the value of the `front-sticky'
  340. property or the `rear-nonsticky' property.  For example, if a character
  341. has a `rear-nonsticky' property whose value is `(face read-only)', then
  342. insertion after the character does not receive its `face' property its
  343. or `read-only' property (if any), but does receive any other properties
  344. it has.
  345.  
  346.    The merging of properties when both sides of the insertion are sticky
  347. takes place one property at a time.  If the preceding character is
  348. `rear-sticky' for the property, and the property is non-`nil', it
  349. dominates.  Otherwise, the following character's property value is used
  350. if it is `front-sticky' for that property.
  351.  
  352. 
  353. File: elisp,  Node: Not Intervals,  Prev: Sticky Properties,  Up: Text Properties
  354.  
  355. Why Text Properties are not Intervals
  356. -------------------------------------
  357.  
  358.    Some editors that support adding attributes to text in the buffer do
  359. so by letting the user specify "intervals" within the text, and adding
  360. the properties to the intervals.  Those editors permit the user or the
  361. programmer to determine where individual intervals start and end.  We
  362. deliberately provided a different sort of interface in Emacs Lisp to
  363. avoid certain paradoxical behavior associated with text modification.
  364.  
  365.    If the actual subdivision into intervals is meaningful, that means
  366. you can distinguish between a buffer that is just one interval with a
  367. certain property, and a buffer containing the same text subdivided into
  368. two intervals, both of which have that property.
  369.  
  370.    Suppose you take the buffer with just one interval and kill part of
  371. the text.  The text remaining in the buffer is one interval, and the
  372. copy in the kill ring (and the undo list) becomes a separate interval.
  373. Then if you undo the kill, you get two intervals with the same
  374. properties.  Thus, the distinction can't be preserved when editing
  375. happens.
  376.  
  377.    But suppose we "fix" this problem by coalescing the two intervals
  378. when the text is inserted.  That works fine if the buffer originally was
  379. a single interval.  But if it was two intervals, and the killed text
  380. equals one of them, then undoing the kill yields just one interval.
  381. Again, the distinction can't be preserved.
  382.  
  383.    Insertion of text at the border between intervals also raises
  384. questions that have no satisfactory answer.
  385.  
  386.    However, it is easy to arrange for editing to behave consistently for
  387. questions of the form, "What are the properties of this character?" So
  388. we have decided these are the only questions that make sense; we have
  389. not implemented asking questions about where intervals start or end.
  390.  
  391.    For practical purposes, the property search functions serve in place
  392. of explicit interval boundaries.  You can think of them as finding the
  393. boundaries of intervals, assuming that intervals are always coalesced
  394. whenever possible.  *Note Property Search::.
  395.  
  396.    Emacs also provides explicit intervals as a presentation feature; see
  397. *Note Overlays::.
  398.  
  399. 
  400. File: elisp,  Node: Substitution,  Next: Underlining,  Prev: Text Properties,  Up: Text
  401.  
  402. Substituting for a Character Code
  403. =================================
  404.  
  405.    The following functions replace characters within a specified region
  406. based on their character codes.
  407.  
  408.  - Function: subst-char-in-region START END OLD-CHAR NEW-CHAR &optional
  409.           NOUNDO
  410.      This function replaces all occurrences of the character OLD-CHAR
  411.      with the character NEW-CHAR in the region of the current buffer
  412.      defined by START and END.
  413.  
  414.      If NOUNDO is non-`nil', then `subst-char-in-region' does not
  415.      record the change for undo and does not mark the buffer as
  416.      modified.  This feature is useful for changes which are not
  417.      considered significant, such as when Outline mode changes visible
  418.      lines to invisible lines and vice versa.
  419.  
  420.      `subst-char-in-region' does not move point and returns `nil'.
  421.  
  422.           ---------- Buffer: foo ----------
  423.           This is the contents of the buffer before.
  424.           ---------- Buffer: foo ----------
  425.           
  426.           (subst-char-in-region 1 20 ?i ?X)
  427.                => nil
  428.           
  429.           ---------- Buffer: foo ----------
  430.           ThXs Xs the contents of the buffer before.
  431.           ---------- Buffer: foo ----------
  432.  
  433.  - Function: translate-region START END TABLE
  434.      This function applies a translation table to the characters in the
  435.      buffer between positions START and END.
  436.  
  437.      The translation table TABLE is a string; `(aref TABLE OCHAR)'
  438.      gives the translated character corresponding to OCHAR.  If the
  439.      length of TABLE is less than 256, any characters with codes larger
  440.      than the length of TABLE are not altered by the translation.
  441.  
  442.      The return value of `translate-region' is the number of characters
  443.      which were actually changed by the translation.  This does not
  444.      count characters which were mapped into themselves in the
  445.      translation table.
  446.  
  447.      This function is available in Emacs versions 19 and later.
  448.  
  449. 
  450. File: elisp,  Node: Underlining,  Next: Registers,  Prev: Substitution,  Up: Text
  451.  
  452. Underlining
  453. ===========
  454.  
  455.    The underlining commands are somewhat obsolete.  The
  456. `underline-region' function actually inserts `_^H' before each
  457. appropriate character in the region.  This command provides a minimal
  458. text formatting feature that might work on your printer; however, we
  459. recommend instead that you use more powerful text formatting facilities,
  460. such as Texinfo.
  461.  
  462.  - Command: underline-region START END
  463.      This function underlines all nonblank characters in the region
  464.      defined by START and END.  That is, an underscore character and a
  465.      backspace character are inserted just before each non-whitespace
  466.      character in the region.  The backspace characters are intended to
  467.      cause overstriking, but in Emacs they display as either `\010' or
  468.      `^H', depending on the setting of `ctl-arrow'.  There is no way to
  469.      see the effect of the overstriking within Emacs.  The value is
  470.      `nil'.
  471.  
  472.  - Command: ununderline-region START END
  473.      This function removes all underlining (overstruck underscores) in
  474.      the region defined by START and END.  The value is `nil'.
  475.  
  476. 
  477. File: elisp,  Node: Registers,  Next: Change Hooks,  Prev: Underlining,  Up: Text
  478.  
  479. Registers
  480. =========
  481.  
  482.    A register is a sort of variable used in Emacs editing that can hold
  483. a marker, a string, a rectangle, a window configuration (of one frame),
  484. or a frame configuration (of all frames).  Each register is named by a
  485. single character.  All characters, including control and meta characters
  486. (but with the exception of `C-g'), can be used to name registers.
  487. Thus, there are 255 possible registers.  A register is designated in
  488. Emacs Lisp by a character which is its name.
  489.  
  490.    The functions in this section return unpredictable values unless
  491. otherwise stated.
  492.  
  493.  - Variable: register-alist
  494.      This variable is an alist of elements of the form `(NAME .
  495.      cONTENTS)'.  Normally, there is one element for each Emacs
  496.      register that has been used.
  497.  
  498.      The object NAME is a character (an integer) identifying the
  499.      register.  The object CONTENTS is a string, marker, or list
  500.      representing the register contents.  A string represents text
  501.      stored in the register.  A marker represents a position.  A list
  502.      represents a rectangle; its elements are strings, one per line of
  503.      the rectangle.
  504.  
  505.  - Command: view-register REG
  506.      This command displays what is contained in register REG.
  507.  
  508.  - Function: get-register REG
  509.      This function returns the contents of the register REG, or `nil'
  510.      if it has no contents.
  511.  
  512.  - Function: set-register REG VALUE
  513.      This function sets the contents of register REG to VALUE.  A
  514.      register can be set to any value, but the other register functions
  515.      expect only certain data types.  The return value is VALUE.
  516.  
  517.  - Command: point-to-register REG
  518.      This command stores both the current location of point and the
  519.      current buffer in register REG as a marker.
  520.  
  521.  - Command: jump-to-register REG
  522.  - Command: register-to-point REG
  523.      This command restores the status recorded in register REG.
  524.  
  525.      If REG contains a marker, it moves point to the position stored in
  526.      the marker.  Since both the buffer and the location within the
  527.      buffer are stored by the `point-to-register' function, this
  528.      command can switch you to another buffer.
  529.  
  530.      If REG contains a window configuration or a frame configuration.
  531.      `jump-to-register' restores that configuration.
  532.  
  533.  - Command: insert-register REG &optional BEFOREP
  534.      This command inserts contents of register REG into the current
  535.      buffer.
  536.  
  537.      Normally, this command puts point before the inserted text, and the
  538.      mark after it.  However, if the optional second argument BEFOREP
  539.      is non-`nil', it puts the mark before and point after.  You can
  540.      pass a non-`nil' second argument BEFOREP to this function
  541.      interactively by supplying any prefix argument.
  542.  
  543.      If the register contains a rectangle, then the rectangle is
  544.      inserted with its upper left corner at point.  This means that
  545.      text is inserted in the current line and underneath it on
  546.      successive lines.
  547.  
  548.      If the register contains something other than saved text (a
  549.      string) or a rectangle (a list), currently useless things happen.
  550.      This may be changed in the future.
  551.  
  552.  - Command: copy-to-register REG START END &optional DELETE-FLAG
  553.      This command copies the region from START to END into register
  554.      REG.  If DELETE-FLAG is non-`nil', it deletes the region from the
  555.      buffer after copying it into the register.
  556.  
  557.  - Command: prepend-to-register REG START END &optional DELETE-FLAG
  558.      This command prepends the region from START to END into register
  559.      REG.  If DELETE-FLAG is non-`nil', it deletes the region from the
  560.      buffer after copying it to the register.
  561.  
  562.  - Command: append-to-register REG START END &optional DELETE-FLAG
  563.      This command appends the region from START to END to the text
  564.      already in register REG.  If DELETE-FLAG is non-`nil', it deletes
  565.      the region from the buffer after copying it to the register.
  566.  
  567.  - Command: copy-rectangle-to-register REG START END &optional
  568.           DELETE-FLAG
  569.      This command copies a rectangular region from START to END into
  570.      register REG.  If DELETE-FLAG is non-`nil', it deletes the region
  571.      from the buffer after copying it to the register.
  572.  
  573.  - Command: window-configuration-to-register REG
  574.      This function stores the window configuration of the selected
  575.      frame in register REG.
  576.  
  577.  - Command: frame-configuration-to-register REG
  578.      This function stores the current frame configuration in register
  579.      REG.
  580.  
  581. 
  582. File: elisp,  Node: Change Hooks,  Prev: Registers,  Up: Text
  583.  
  584. Change Hooks
  585. ============
  586.  
  587.    These hook variables let you arrange to take notice of all changes in
  588. all buffers (or in a particular buffer, if you make them buffer-local).
  589. See also *Note Special Properties::, for how to detect changes to
  590. specific parts of the text.
  591.  
  592.    The functions you use in these hooks should save and restore the
  593. match data if they do anything that uses regular expressions;
  594. otherwise, they will interfere in bizarre ways with the editing
  595. operations that call them.
  596.  
  597.  - Variable: before-change-function
  598.      If this variable is non-`nil', then it should be a function; the
  599.      function is called before any buffer modification.  Its arguments
  600.      are the beginning and end of the region that is going to change,
  601.      represented as integers.  The buffer that's about to change is
  602.      always the current buffer.
  603.  
  604.  - Variable: after-change-function
  605.      If this variable is non-`nil', then it should be a function; the
  606.      function is called after any buffer modification.  It receives
  607.      three arguments: the beginning and end of the region just changed,
  608.      and the length of the text that existed before the change.  (To
  609.      get the current length, subtract the region beginning from the
  610.      region end.) All three arguments are integers.  The buffer that's
  611.      about to change is always the current buffer.
  612.  
  613.    Both of these variables are temporarily bound to `nil' during the
  614. time that either of these hooks is running.  This means that if one of
  615. these functions changes the buffer, that change won't run these
  616. functions.  If you do want the hook function to be run recursively,
  617. write your hook functions to bind these variables back to their usual
  618. values.
  619.  
  620.  - Variable: first-change-hook
  621.      This variable is a normal hook; its hook functions are run using
  622.      `run-hooks' whenever a buffer is changed that was previously in
  623.      the unmodified state.
  624.  
  625.    The variables described in this section are meaningful only starting
  626. with Emacs version 19.
  627.  
  628. 
  629. File: elisp,  Node: Searching and Matching,  Next: Syntax Tables,  Prev: Text,  Up: Top
  630.  
  631. Searching and Matching
  632. **********************
  633.  
  634.    GNU Emacs provides two ways to search through a buffer for specified
  635. text: exact string searches and regular expression searches.  After a
  636. regular expression search, you can identify the text matched by parts of
  637. the regular expression by examining the "match data".
  638.  
  639. * Menu:
  640.  
  641. * String Search::         Search for an exact match.
  642. * Regular Expressions::   Describing classes of strings.
  643. * Regexp Search::         Searching for a match for a regexp.
  644. * Replacement::          Internals of `query-replace'.
  645. * Match Data::            Finding out which part of the text matched
  646.                             various parts of a regexp, after regexp search.
  647. * Standard Regexps::      Useful regexps for finding sentences, pages,...
  648. * Searching and Case::    Case-independent or case-significant searching.
  649.  
  650. 
  651. File: elisp,  Node: String Search,  Next: Regular Expressions,  Up: Searching and Matching
  652.  
  653. Searching for Strings
  654. =====================
  655.  
  656.    These are the primitive functions for searching through the text in a
  657. buffer.  They are meant for use in programs, but you may call them
  658. interactively.  If you do so, they prompt for the search string; LIMIT
  659. and NOERROR are set to `nil', and REPEAT is set to 1.
  660.  
  661.  - Command: search-forward STRING &optional LIMIT NOERROR REPEAT
  662.      This function searches forward from point for an exact match for
  663.      STRING.  If successful, it sets point to the end of the occurrence
  664.      found, and returns the new value of point.  If no match is found,
  665.      the value and side effects depend on NOERROR (see below).
  666.  
  667.      In the following example, point is positioned at the beginning of
  668.      the line.  Then `(search-forward "fox")' is evaluated in the
  669.      minibuffer and point is left after the last letter of `fox':
  670.  
  671.           ---------- Buffer: foo ----------
  672.           -!-The quick brown fox jumped over the lazy dog.
  673.           ---------- Buffer: foo ----------
  674.           
  675.           (search-forward "fox")
  676.                => t
  677.           
  678.           ---------- Buffer: foo ----------
  679.           The quick brown fox-!- jumped over the lazy dog.
  680.           ---------- Buffer: foo ----------
  681.  
  682.      The argument LIMIT specifies the upper bound to the search.  (It
  683.      must be a position in the current buffer.)  No match extending
  684.      after that position is accepted.  If LIMIT is omitted or `nil', it
  685.      defaults to the end of the accessible portion of the buffer.
  686.  
  687.      What happens when the search fails depends on the value of
  688.      NOERROR.  If NOERROR is `nil', a `search-failed' error is
  689.      signaled.  If NOERROR is `t', `search-forward' returns `nil' and
  690.      does nothing.  If NOERROR is neither `nil' nor `t', then
  691.      `search-forward' moves point to the upper bound and returns `nil'.
  692.      (It would be more consistent now to return the new position of
  693.      point in that case, but some programs may depend on a value of
  694.      `nil'.)
  695.  
  696.      If REPEAT is non-`nil', then the search is repeated that many
  697.      times.  Point is positioned at the end of the last match.
  698.  
  699.  - Command: search-backward STRING &optional LIMIT NOERROR REPEAT
  700.      This function searches backward from point for STRING.  It is just
  701.      like `search-forward' except that it searches backwards and leaves
  702.      point at the beginning of the match.
  703.  
  704.  - Command: word-search-forward STRING &optional LIMIT NOERROR REPEAT
  705.      This function searches forward from point for a "word" match for
  706.      STRING.  If it finds a match, it sets point to the end of the
  707.      match found, and returns the new value of point.
  708.  
  709.      A word search differs from a simple string search in that a word
  710.      search *requires* that the words it searches for are present as
  711.      entire words (searching for the word `ball' does not match the word
  712.      `balls'), and punctuation and spacing are ignored (searching for
  713.      `ball boy' does match `ball.  Boy!').
  714.  
  715.      In this example, point is first placed at the beginning of the
  716.      buffer; the search leaves it between the `y' and the `!'.
  717.  
  718.           ---------- Buffer: foo ----------
  719.           -!-He said "Please!  Find
  720.           the ball boy!"
  721.           ---------- Buffer: foo ----------
  722.           
  723.           (word-search-forward "Please find the ball, boy.")
  724.                => t
  725.           
  726.           ---------- Buffer: foo ----------
  727.           He said "Please!  Find
  728.           the ball boy-!-!"
  729.           ---------- Buffer: foo ----------
  730.  
  731.      If LIMIT is non-`nil' (it must be a position in the current
  732.      buffer), then it is the upper bound to the search.  The match
  733.      found must not extend after that position.
  734.  
  735.      If NOERROR is `t', then `word-search-forward' returns `nil' when a
  736.      search fails, instead of signaling an error.  If NOERROR is
  737.      neither `nil' nor `t', then `word-search-forward' moves point to
  738.      LIMIT (or the end of the buffer) and returns `nil'.
  739.  
  740.      If REPEAT is non-`nil', then the search is repeated that many
  741.      times.  Point is positioned at the end of the last match.
  742.  
  743.  - Command: word-search-backward STRING &optional LIMIT NOERROR REPEAT
  744.      This function searches backward from point for a word match to
  745.      STRING.  This function is just like `word-search-forward' except
  746.      that it searches backward and normally leaves point at the
  747.      beginning of the match.
  748.  
  749. 
  750. File: elisp,  Node: Regular Expressions,  Next: Regexp Search,  Prev: String Search,  Up: Searching and Matching
  751.  
  752. Regular Expressions
  753. ===================
  754.  
  755.    A "regular expression" ("regexp", for short) is a pattern that
  756. denotes a (possibly infinite) set of strings.  Searching for matches for
  757. a regexp is a very powerful operation.  This section explains how to
  758. write regexps; the following section says how to search for them.
  759.  
  760. * Menu:
  761.  
  762. * Syntax of Regexps::       Rules for writing regular expressions.
  763. * Regexp Example::          Illustrates regular expression syntax.
  764.  
  765. 
  766. File: elisp,  Node: Syntax of Regexps,  Next: Regexp Example,  Up: Regular Expressions
  767.  
  768. Syntax of Regular Expressions
  769. -----------------------------
  770.  
  771.    Regular expressions have a syntax in which a few characters are
  772. special constructs and the rest are "ordinary".  An ordinary character
  773. is a simple regular expression which matches that character and nothing
  774. else.  The special characters are `$', `^', `.', `*', `+', `?', `[',
  775. `]' and `\'; no new special characters will be defined in the future.
  776. Any other character appearing in a regular expression is ordinary,
  777. unless a `\' precedes it.
  778.  
  779.    For example, `f' is not a special character, so it is ordinary, and
  780. therefore `f' is a regular expression that matches the string `f' and
  781. no other string.  (It does *not* match the string `ff'.)  Likewise, `o'
  782. is a regular expression that matches only `o'.
  783.  
  784.    Any two regular expressions A and B can be concatenated.  The result
  785. is a regular expression which matches a string if A matches some amount
  786. of the beginning of that string and B matches the rest of the string.
  787.  
  788.    As a simple example, we can concatenate the regular expressions `f'
  789. and `o' to get the regular expression `fo', which matches only the
  790. string `fo'.  Still trivial.  To do something more powerful, you need
  791. to use one of the special characters.  Here is a list of them:
  792.  
  793. `. (Period)'
  794.      is a special character that matches any single character except a
  795.      newline.  Using concatenation, we can make regular expressions
  796.      like `a.b' which matches any three-character string which begins
  797.      with `a' and ends with `b'.
  798.  
  799. `*'
  800.      is not a construct by itself; it is a suffix that means the
  801.      preceding regular expression is to be repeated as many times as
  802.      possible.  In `fo*', the `*' applies to the `o', so `fo*' matches
  803.      one `f' followed by any number of `o's.  The case of zero `o's is
  804.      allowed: `fo*' does match `f'.
  805.  
  806.      `*' always applies to the *smallest* possible preceding
  807.      expression.  Thus, `fo*' has a repeating `o', not a repeating `fo'.
  808.  
  809.      The matcher processes a `*' construct by matching, immediately, as
  810.      many repetitions as can be found.  Then it continues with the rest
  811.      of the pattern.  If that fails, backtracking occurs, discarding
  812.      some of the matches of the `*'-modified construct in case that
  813.      makes it possible to match the rest of the pattern.  For example,
  814.      matching `ca*ar' against the string `caaar', the `a*' first tries
  815.      to match all three `a's; but the rest of the pattern is `ar' and
  816.      there is only `r' left to match, so this try fails.  The next
  817.      alternative is for `a*' to match only two `a's.  With this choice,
  818.      the rest of the regexp matches successfully.
  819.  
  820. `+'
  821.      is a suffix character similar to `*' except that it must match the
  822.      preceding expression at least once.  So, for example, `ca+r' will
  823.      match the strings `car' and `caaaar' but not the string `cr',
  824.      whereas `ca*r' would match all three strings.
  825.  
  826. `?'
  827.      is a suffix character similar to `*' except that it can match the
  828.      preceding expression either once or not at all.  For example,
  829.      `ca?r' will match `car' or `cr'; nothing else.
  830.  
  831. `[ ... ]'
  832.      `[' begins a "character set", which is terminated by a `]'.  In
  833.      the simplest case, the characters between the two form the set.
  834.      Thus, `[ad]' matches either one `a' or one `d', and `[ad]*'
  835.      matches any string composed of just `a's and `d's (including the
  836.      empty string), from which it follows that `c[ad]*r' matches `cr',
  837.      `car', `cdr', `caddaar', etc.
  838.  
  839.      Character ranges can also be included in a character set, by
  840.      writing two characters with a `-' between them.  Thus, `[a-z]'
  841.      matches any lower case letter.  Ranges may be intermixed freely
  842.      with individual characters, as in `[a-z$%.]', which matches any
  843.      lower case letter or `$', `%' or a period.
  844.  
  845.      Note that the usual special characters are not special any more
  846.      inside a character set.  A completely different set of special
  847.      characters exists inside character sets: `]', `-' and `^'.
  848.  
  849.      To include a `]' in a character set, make it the first character.
  850.      For example, `[]a]' matches `]' or `a'.  To include a `-', write
  851.      `-' as the first or last character in the range.
  852.  
  853.      To include `^', make it other than the first character in the set.
  854.  
  855. `[^ ... ]'
  856.      `[^' begins a "complement character set", which matches any
  857.      character except the ones specified.  Thus, `[^a-z0-9A-Z]' matches
  858.      all characters *except* letters and digits.
  859.  
  860.      `^' is not special in a character set unless it is the first
  861.      character.  The character following the `^' is treated as if it
  862.      were first (thus, `-' and `]' are not special there).
  863.  
  864.      Note that a complement character set can match a newline, unless
  865.      newline is mentioned as one of the characters not to match.
  866.  
  867. `^'
  868.      is a special character that matches the empty string, but only at
  869.      the beginning of a line in the text being matched.  Otherwise it
  870.      fails to match anything.  Thus, `^foo' matches a `foo' which occurs
  871.      at the beginning of a line.
  872.  
  873.      When matching a string, `^' matches at the beginning of the string
  874.      or after a newline character `\n'.
  875.  
  876. `$'
  877.      is similar to `^' but matches only at the end of a line.  Thus,
  878.      `x+$' matches a string of one `x' or more at the end of a line.
  879.  
  880.      When matching a string, `$' matches at the end of the string or
  881.      before a newline character `\n'.
  882.  
  883. `\'
  884.      has two functions: it quotes the special characters (including
  885.      `\'), and it introduces additional special constructs.
  886.  
  887.      Because `\' quotes special characters, `\$' is a regular
  888.      expression which matches only `$', and `\[' is a regular
  889.      expression which matches only `[', and so on.
  890.  
  891.      Note that `\' also has special meaning in the read syntax of Lisp
  892.      strings (*note String Type::.), and must be quoted with `\'.  For
  893.      example, the regular expression that matches the `\' character is
  894.      `\\'.  To write a Lisp string that contains the characters `\\',
  895.      Lisp syntax requires you to quote each `\' with another `\'.
  896.      Therefore, the read syntax for a regular expression matching `\'
  897.      is `"\\\\"'.
  898.  
  899.    *Please note:* for historical compatibility, special characters are
  900. treated as ordinary ones if they are in contexts where their special
  901. meanings make no sense.  For example, `*foo' treats `*' as ordinary
  902. since there is no preceding expression on which the `*' can act.  It is
  903. poor practice to depend on this behavior; better to quote the special
  904. character anyway, regardless of where it appears.
  905.  
  906.    For the most part, `\' followed by any character matches only that
  907. character.  However, there are several exceptions: characters which,
  908. when preceded by `\', are special constructs.  Such characters are
  909. always ordinary when encountered on their own.  Here is a table of `\'
  910. constructs:
  911.  
  912. `\|'
  913.      specifies an alternative.  Two regular expressions A and B with
  914.      `\|' in between form an expression that matches anything that
  915.      either A or B matches.
  916.  
  917.      Thus, `foo\|bar' matches either `foo' or `bar' but no other string.
  918.  
  919.      `\|' applies to the largest possible surrounding expressions.
  920.      Only a surrounding `\( ... \)' grouping can limit the grouping
  921.      power of `\|'.
  922.  
  923.      Full backtracking capability exists to handle multiple uses of
  924.      `\|'.
  925.  
  926. `\( ... \)'
  927.      is a grouping construct that serves three purposes:
  928.  
  929.        1. To enclose a set of `\|' alternatives for other operations.
  930.           Thus, `\(foo\|bar\)x' matches either `foox' or `barx'.
  931.  
  932.        2. To enclose a complicated expression for a suffix character
  933.           such as `*' to operate on.  Thus, `ba\(na\)*' matches
  934.           `bananana', etc., with any (zero or more) number of `na'
  935.           strings.
  936.  
  937.        3. To record a matched substring for future reference.
  938.  
  939.      This last application is not a consequence of the idea of a
  940.      parenthetical grouping; it is a separate feature which happens to
  941.      be assigned as a second meaning to the same `\( ... \)' construct
  942.      because there is no conflict in practice between the two meanings.
  943.      Here is an explanation of this feature:
  944.  
  945. `\DIGIT'
  946.      matches the same text which is matched the DIGITth time by a
  947.      previous `\( ... \)' construct.
  948.  
  949.      In other words, after the end of a `\( ... \)' construct.  the
  950.      matcher remembers the beginning and end of the text matched by
  951.      that construct.  Then, later on in the regular expression, you can
  952.      use `\' followed by DIGIT to mean "match the same text matched the
  953.      DIGITth time by the `\( ... \)' construct."
  954.  
  955.      The strings matching the first nine `\( ... \)' constructs
  956.      appearing in a regular expression are assigned numbers 1 through 9
  957.      in the order that the open parentheses appear in the regular
  958.      expression.  So you can use `\1' through `\9' to refer to the text
  959.      matched by the corresponding `\( ... \)' constructs.
  960.  
  961.      For example, `\(.*\)\1' matches any newline-free string that is
  962.      composed of two identical halves.  The `\(.*\)' matches the first
  963.      half, which may be anything, but the `\1' that follows must match
  964.      the same exact text.
  965.  
  966. `\`'
  967.      matches the empty string, provided it is at the beginning of the
  968.      buffer or string being matched against.
  969.  
  970. `\''
  971.      matches the empty string, provided it is at the end of the buffer
  972.      or string being matched against.
  973.  
  974. `\='
  975.      matches the empty string, provided it is at point.  (This
  976.      construct is not defined when matching against a string.)
  977.  
  978. `\b'
  979.      matches the empty string, provided it is at the beginning or end
  980.      of a word.  Thus, `\bfoo\b' matches any occurrence of `foo' as a
  981.      separate word.  `\bballs?\b' matches `ball' or `balls' as a
  982.      separate word.
  983.  
  984. `\B'
  985.      matches the empty string, provided it is *not* at the beginning or
  986.      end of a word.
  987.  
  988. `\<'
  989.      matches the empty string, provided it is at the beginning of a
  990.      word.
  991.  
  992. `\>'
  993.      matches the empty string, provided it is at the end of a word.
  994.  
  995. `\w'
  996.      matches any word-constituent character.  The editor syntax table
  997.      determines which characters these are.  *Note Syntax Tables::.
  998.  
  999. `\W'
  1000.      matches any character that is not a word-constituent.
  1001.  
  1002. `\sCODE'
  1003.      matches any character whose syntax is CODE.  Here CODE is a
  1004.      character which represents a syntax code: thus, `w' for word
  1005.      constituent, `-' for whitespace, `(' for open parenthesis, etc.
  1006.      *Note Syntax Tables::, for a list of the codes.
  1007.  
  1008. `\SCODE'
  1009.      matches any character whose syntax is not CODE.
  1010.  
  1011.    Not every string is a valid regular expression.  For example, any
  1012. string with unbalanced square brackets is invalid, and so is a string
  1013. that ends with a single `\'.  If an invalid regular expression is
  1014. passed to any of the search functions, an `invalid-regexp' error is
  1015. signaled.
  1016.  
  1017.  - Function: regexp-quote STRING
  1018.      This function returns a regular expression string which matches
  1019.      exactly STRING and nothing else.  This allows you to request an
  1020.      exact string match when calling a function that wants a regular
  1021.      expression.
  1022.  
  1023.           (regexp-quote "^The cat$")
  1024.                => "\\^The cat\\$"
  1025.  
  1026.      One use of `regexp-quote' is to combine an exact string match with
  1027.      context described as a regular expression.  For example, this
  1028.      searches for the string which is the value of `string', surrounded
  1029.      by whitespace:
  1030.  
  1031.           (re-search-forward
  1032.            (concat "\\s " (regexp-quote string) "\\s "))
  1033.  
  1034. 
  1035. File: elisp,  Node: Regexp Example,  Prev: Syntax of Regexps,  Up: Regular Expressions
  1036.  
  1037. Complex Regexp Example
  1038. ----------------------
  1039.  
  1040.    Here is a complicated regexp, used by Emacs to recognize the end of a
  1041. sentence together with any whitespace that follows.  It is the value of
  1042. the variable `sentence-end'.
  1043.  
  1044.    First, we show the regexp as a string in Lisp syntax to enable you to
  1045. distinguish the spaces from the tab characters.  The string constant
  1046. begins and ends with a double-quote.  `\"' stands for a double-quote as
  1047. part of the string, `\\' for a backslash as part of the string, `\t'
  1048. for a tab and `\n' for a newline.
  1049.  
  1050.      "[.?!][]\"')}]*\\($\\|\t\\|  \\)[ \t\n]*"
  1051.  
  1052.    In contrast, if you evaluate the variable `sentence-end', you will
  1053. see the following:
  1054.  
  1055.      sentence-end
  1056.      =>
  1057.      "[.?!][]\"')}]*\\($\\|  \\|  \\)[
  1058.      ]*"
  1059.  
  1060. In this case, the tab and carriage return are the actual characters.
  1061.  
  1062.    This regular expression contains four parts in succession and can be
  1063. deciphered as follows:
  1064.  
  1065. `[.?!]'
  1066.      The first part of the pattern consists of three characters, a
  1067.      period, a question mark and an exclamation mark, within square
  1068.      brackets.  The match must begin with one of these three characters.
  1069.  
  1070. `[]\"')}]*'
  1071.      The second part of the pattern matches any closing braces and
  1072.      quotation marks, zero or more of them, that may follow the period,
  1073.      question mark or exclamation mark.  The `\"' is Lisp syntax for a
  1074.      double-quote in a string.  The `*' at the end indicates that the
  1075.      immediately preceding regular expression (a character set, in this
  1076.      case) may be repeated zero or more times.
  1077.  
  1078. `\\($\\|\t\\|  \\)'
  1079.      The third part of the pattern matches the whitespace that follows
  1080.      the end of a sentence: the end of a line, or a tab, or two spaces.
  1081.      The double backslashes are needed to prevent Emacs from reading
  1082.      the parentheses and vertical bars as part of the search pattern;
  1083.      the parentheses are used to mark the group and the vertical bars
  1084.      are used to indicated that the patterns to either side of them are
  1085.      alternatives.  The dollar sign is used to match the end of a line.
  1086.      The tab character is written using `\t' and the two spaces are
  1087.      written as themselves.
  1088.  
  1089. `[ \t\n]*'
  1090.      Finally, the last part of the pattern indicates that the end of
  1091.      the line or the whitespace following the period, question mark or
  1092.      exclamation mark may, but need not, be followed by additional
  1093.      whitespace.
  1094.  
  1095.